package com.estun.backroundManagementService.modules.position.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.estun.backroundManagementService.modules.position.dto.FeedingPortParam;
import com.estun.backroundManagementService.modules.position.mapper.FeedingPortMapper;
import com.estun.backroundManagementService.modules.position.model.FeedingPort;
import com.estun.backroundManagementService.modules.position.service.FeedingPortService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class FeedingPortServiceImpl extends ServiceImpl<FeedingPortMapper, FeedingPort> implements FeedingPortService {

    @Override
    public List<FeedingPort> listByStationId(String stationId) {
        QueryWrapper<FeedingPort> feedingPortQueryWrapper = new QueryWrapper<>();
        feedingPortQueryWrapper.lambda().eq(FeedingPort::getStationId, stationId);
        return list(feedingPortQueryWrapper);
    }

    @Transactional
    @Override
    public boolean bindFeedingPort(FeedingPortParam feedingPortParam) {
        QueryWrapper<FeedingPort> feedingPortQueryWrapper = new QueryWrapper<>();
        feedingPortQueryWrapper.lambda().eq(FeedingPort::getStationId, feedingPortParam.getStationId());
        remove(feedingPortQueryWrapper);
        List<FeedingPort> list = feedingPortParam.getFeedingPortList();
        return saveBatch(list);
    }


}
